package com.sky.controller.user;

import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RequestMapping("/user/setmeal")
@RestController
@Api(tags = "套餐浏览接口")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @GetMapping("/list")
    @ApiOperation("根据id查询套餐")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    public Result<List<Setmeal>> setmealList(Integer categoryId) {
        List<Setmeal> setmealList;
        setmealList = setmealService.search(categoryId);
        return Result.success(setmealList);
    }


    /**
     * 根据套餐id查询菜品信息
     * @param id
     * @return
     */
    @ApiOperation("根据套餐id查询菜品信息")
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> getBySetID(@PathVariable Integer id) {
        log.info("根据套餐id查询菜品信息{}", id);
        List<DishItemVO> dishItemVOList = new ArrayList<>();
        dishItemVOList=setmealService.getBySetmealId(id);
        return Result.success(dishItemVOList);
    }
}
